/* eslint-disable jsdoc/ts-no-empty-object-type */
// @ts-check
import path from "node:path";

/**
 * @power ms-vscode.ts-file-path-support
 * @template TBaseDir
 * @typedef {string & { baseDir?: TBaseDir }} RelativeFilePath
 */
/**
 * @type {Map<string, string>}
 */
export const pathMap = new Map();

/**
 * @development
 * @description Resolve relative path to absolute path.
 * @param {RelativeFilePath<'$dir/..'>} s
 * @returns {(string & {})}
 */
export const p2 = (s) => {
  if (pathMap.has(s)) {
    return /** @type {string} */ (pathMap.get(s));
  }
  const p = path.resolve(import.meta.dirname, "..", s);
  pathMap.set(s, p);
  return p;
};

/**
 * @production
 * @description Resolve relative path to absolute path.
 * @param {string[]} s
 * @returns {string}
 */
export const _p2 = (...s) => path.resolve(import.meta.dirname, ...s);
